<title>模块管理</title> 
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>模块</cite></a>
    <a><cite>模块管理</cite></a>
  </div>
</div>
<h1>系统功能模块维护</h1></br>
<div id="test1"></div>	 
<script>
layui.use(['tree','jquery','form'], function(){
  var tree = layui.tree;
  var $=layui.jquery;
  var form=layui.form;
$.post(
'http://stuapi.ysdjypt.com/api/GetAllModuleLayUI',
{
    token:'99edc960-8dba-43cf-8af8-81c408a2cb6b'
},function(res){
    //渲染
  var inst1 = tree.render({
    elem: '#test1'  //绑定元素
       ,data:res
       ,edit:['add','update','del']
       ,operate: function(obj){
        var type = obj.type; //得到操作类型：add、edit、del
        var data = obj.data; //得到当前节点的数据
        var elem = obj.elem; //得到当前节点元素
        
       //Ajax 操作
          var id = data.id; //得到节点索引
         if(type === 'add'){ //增加节点 
        $('#parentId').val(id);
       layer.open({
               type:1,
               title:'添加子节点',
               area:['500px','600px'],
         content: $('#addModule') //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
       }); 
       form.on('submit(add)', function(data){        
       $.post(
          'http://stuapi.ysdjypt.com/api/CreateModule'
          ,{
          name:data.field.name,
          path:data.field.path,
          weight:data.field.weight,
          parentId:id
          ,token:'99edc960-8dba-43cf-8af8-81c408a2cb6b'
          },
          function(res){
            location.reload();        
          },'json'
          );
          layer.close(index); //执行关闭 
       });
          //返回 key 值
          return 123;
         } else if(type === 'update'){ //修改节点
              $.post(
                'http://stuapi.ysdjypt.com/api/GetModuleById',
                {
                  id:id,
                  token:'99edc960-8dba-43cf-8af8-81c408a2cb6b'
                },function(res){
                  $("#parentId2").val(JSON.parse(res.message).parentId);
                },'json'
              );
              $('#mId').val(id);
              form.val('dd', {
                'name':data.title,//模块名称(节点标题)
              }); //表单回显
              layer.open({
                type: 1,
                title: '编辑模块',
                area: ['500px', '600px'],
                content: $('#editModule') //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
              });
              //监听提交
              form.on('submit(edit)', function(data) {
                $.post(
                  'http://stuapi.ysdjypt.com/api/UpdateModule',
                  data.field,
                  function(res){
                    location.reload();
                  },'json'
                );
                return false; //阻止表单提交
              }); 
         } else if(type === 'del'){ //删除节点 
       $.post(
       'http://stuapi.ysdjypt.com/api/DeleteModule',
       {     
        mId:id,
       token:'99edc960-8dba-43cf-8af8-81c408a2cb6b'
       }
       ); 
        };
      }
    ,data:res
    });
},'json'
);
});
</script>
<div id="addModule" style="display: none;">
  <h2>系统功能模块维护</h2></br>
  <form id="ff" class="layui-form" action="" lay-filter="ff">
    <input type="hidden" name="token" value="d5abbc8b-09e2-4aa2-a8e6-5795fa7cfe89"/>
   <div class="layui-form-item">
    <label class="layui-form-label">父节点编号</label>
    <div class="layui-input-inline">
      <input type="text" id="parentId" name="parentId"  placeholder="请输入模块名称" autocomplete="off" class="layui-input">
    </div>
  </div>
    <div class="layui-form-item">
      <label class="layui-form-label">节点名称</label>
      <div class="layui-input-inline">
        <input type="text" id="name" name="name"  placeholder="请输入模块名称" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">路径</label>
      <div class="layui-input-inline">
        <input type="text" id="path" name="path"  placeholder="请输入模块对应的路径" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">权重</label>
      <div class="layui-input-inline">
        <input type="text" id="weight" name="weight" placeholder="请输入权重整数" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>
  </div>
<div id="editModule" style="display: none;">
  <button id="btn" type="button" class="layui-btn">一个标准的按钮</button>
  <form id="dd" class="layui-form" action="" lay-filter="dd">
    <input type="hidden" name="token" value="d5abbc8b-09e2-4aa2-a8e6-5795fa7cfe89" />
  <div class="layui-form-item">
    <label class="layui-form-label">父节点编号</label>
    <div class="layui-input-inline">
      <input type="text" id="parentId2" name="parentId"  placeholder="请输入模块名称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">节点编号</label>
    <div class="layui-input-inline">
      <input type="text" id="mId" name="mId"placeholder="请输入模块名称" autocomplete="off" class="layui-input">
    </div>
  </div>
    <div class="layui-form-item">
      <label class="layui-form-label">模块名称</label>
      <div class="layui-input-inline">
        <input type="text" id="name" name="name"  placeholder="请输入模块名称" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">模块对应的路径</label>
      <div class="layui-input-inline">
        <input type="text" id="path" name="path"  placeholder="请输入模块对应的路径" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">权重整数</label>
      <div class="layui-input-inline">
        <input type="text" id="weight" name="weight" placeholder="请输入权重整数" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>	
  </div>
</script>